#ifndef XX_COMMON_OSIP_THREAD_HH
#define XX_COMMON_OSIP_THREAD_HH
#include "sys_inc.h"


#ifdef WIN32
typedef HANDLE xx_sem;
typedef HANDLE xx_thread_mutex;
typedef HANDLE xx_thread_handle;
#else
typedef sem_t* xx_sem;
typedef pthread_t xx_thread_handle;
typedef pthread_mutex_t* xx_thread_mutex;
#endif


typedef void (*XX_ThreadFun)(void* arg);

xx_sem xx_sem_create(void* attr, int value);

int xx_sem_post(xx_sem sem);

int xx_sem_wait(xx_sem sem);

int xx_sem_destroy(xx_sem sem);

int xx_sem_time_wait(xx_sem sem, int msec);

xx_thread_mutex xx_mutex_create(void* attr);

void xx_mutex_lock(xx_thread_mutex mutex);

void xx_mutex_unlock(xx_thread_mutex mutex);

void xx_mutex_destroy(xx_thread_mutex mutex);

int xx_create_thread(xx_thread_handle* handle, XX_ThreadFun fun, void* arg, void* attr);

int xx_thread_join(xx_thread_handle handle);

#endif